from flask import Blueprint, jsonify, request, session
from flask import render_template
from bt import Bt_api
from decorator import login_required
from flask import current_app
blueprint = Blueprint('/GetIndex', __name__, url_prefix='/GetIndex')


# 获取当前默认文档，切换默认文档
@blueprint.route("/", endpoint='/', methods=['GET', 'POST'])
@login_required
def GetIndex():
    # 实例化宝塔API对象
    bt_api=Bt_api(session.get('bt_url'),session.get('bt_key'))
    if request.method == 'POST':
        Index = request.form['Index']
        data = bt_api.SetIndex(session.get('siteId'), Index)
    
        return jsonify(data)
    
    data = bt_api.GetIndex(session.get('siteId'))
    cdn=current_app.config['CDN']
        

    return render_template('GetIndex.html',data=data,cdn=cdn)